package net.projecteuler.prob;

public class Problem30 implements Runnable {

	@Override
	public void run() {
		int Max = 1000000;
		
		int result = 0;
		for(int i = 10; i < Max; i++){
			int[] digits = digits(i);
			
			int temp = 0;
			for(int j = 0; j < digits.length; j++)
				temp += powerInt(digits[j], 5);
			
			if(temp == i){
				result += i;
				System.out.println(temp);
			}
		}
		
		System.out.println("Total : " + result);
	}
	
	public int[] digits(int value){
		int digitCnt = (int)Math.log10(value) + 1;
		int[] result = new int[digitCnt];
		
		for(int i = 0; i < digitCnt; i++){
			result[i] = value % 10;
			value /= 10;
		}
		
		return result;
	}

	public int powerInt(int base, int power){
		if(power < 0) return 0;
		if(power == 1) return 1;
		
		int result = 1;
		for(int i = 0; i < power; i++)
			result *= base;
		
		return result;
	}
}
